package com.hot100.mid;

import java.util.Arrays;

/**
 * @author zhengTao
 * @version 1.0
 * @description:
 * @date 2022/8/28 15:30
 */
public class Demo30 {
    public static void main(String[] args) {
        int[] nums={1,2,0,1};
        int i = longestConsecutive(nums);
    }

    public static int longestConsecutive(int[] nums) {
           if(nums.length<=0){
               return 0;
           }
        Arrays.sort(nums);
        int i=0;
        int max=1;
        while (i<nums.length-1){
            int lenth=1;
            while (nums[i]+1==nums[i+1]||nums[i]==nums[i+1]) {
                if(nums[i]+1==nums[i+1]){
                    if((i+1)==nums.length-1){
                        lenth++;
                        max=Math.max(max,lenth);
                        i++;
                        break;
                    }
                    lenth++;
                    max=Math.max(max,lenth);
                    i++;
                }else {
                    if((i+1)==nums.length-1){
                        break;
                    }else {
                        i++;
                    }
                }
            }
            i++;
        }
        return max;
    }
}
